<template>
  <div class="head-info">
    <section class="datetime">
      <span class="date">{{year}}年{{month}}月{{date}}日 星期{{day|convertNumToDay}}</span>
      <span class="time">{{hour}}:{{minute}}:{{second}}</span>
    </section>
    <h1 class="title">北京急救信息平台—调度指挥中心</h1>
    <section class="nav">
      <slot></slot>
      <section class="back-wrapper">
        <i class="iconfont">&#xe600;</i>
        <span class="back" @click="GoToIndex">返回首页</span>
      </section>
    </section>
  </div>
</template>

<script>
export default {
  name: "Head",
  data() {
    return {
      year: "",
      month: "",
      date: "",
      hour: "",
      minute: "",
      second: "",
      day: "",
      timer: "",
    };
  },
  filters: {
    convertNumToDay(data) {
      let day = "一";
      switch (data) {
        case 0:
          day = "日";
          break;
        case 1:
          day = "一";
          break;
        case 2:
          day = "二";
          break;
        case 3:
          day = "三";
          break;
        case 4:
          day = "四";
          break;
        case 5:
          day = "五";
          break;
        case 6:
          day = "六";
          break;
      }
      return day;
    },
  },
  mounted() {
    this.timer = setInterval(() => {
      let datetime = new Date();
      this.year = datetime.getFullYear();
      this.month = datetime.getMonth() + 1;
      this.date = datetime.getDate();
      this.day = datetime.getDay();
      this.hour = datetime.getHours();
      this.minute = datetime.getMinutes();
      this.second = datetime.getSeconds();
    }, 1000);
  },
  methods: {
    GoToIndex() {
      this.$router.push({ name: "Index" });
    },
  },
  destroyed() {
    clearInterval(this.timer);
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.head-info {
  background: url("../assets/image/headbg.png") no-repeat;
  background-size: 100% 100%;
  height: 10%;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  position: relative;
}
.datetime {
  position: absolute;
  left: 40px;
  top: 70%;
  font-weight: bold;
  font-size: 18px;
}
.time {
  font-size: 19px;
  margin-left: 10px;
}
.title {
  text-shadow: 1px 1px 1px #fff;
  text-align: center;
  font-size: 30px;
}
.nav {
  position: absolute;
  right: 40px;
  top: 70%;
  display: flex;
  font-size: 19px;
}
.back-wrapper {
  cursor: pointer;
}
</style>